package com.atguigu.lease.web.app.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.atguigu.lease.common.exception.LeaseException;
import com.atguigu.lease.web.app.service.SmsService;
import org.springframework.stereotype.Service;

/**
 * Package: com.atguigu.lease.web.app.service.impl
 *
 * @Description:
 * @Author xiongkunYang
 * @Create 2025/4/23 8:54
 */
@Service
public class SmsServiceImpl implements SmsService {

    private final Client client;

    public SmsServiceImpl(Client client) {
        this.client = client;
    }

    @Override
    public void sendCode(String phone, String verifyCode) {
        try {
            this.client.sendSms(new SendSmsRequest()
                    .setPhoneNumbers(phone)
                    .setSignName("阿里云短信测试")
                    .setTemplateCode("SMS_154950909")
                    .setTemplateParam("{\"code\":\"" + verifyCode + "\"}"));
        } catch (Exception e) {
            throw new LeaseException("验证码发送失败", e);
        }
    }
}